package com.sx.gongzhong.pest;

import com.sx.gongzhong.model.CommentBean;
import com.sx.gongzhong.model.ExposureDetailBean;
import com.sx.gongzhong.model.HeadParamBean;
import com.sx.gongzhong.model.ReplyUserBean;
import com.sx.gongzhong.net.ApiManager;
import com.sx.gongzhong.net.BaseCallBack;
import com.sx.gongzhong.model.BasePageListBean;
import com.sx.gongzhong.view.IExposureDetailView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by XZY on 2018/1/9.
 * 爆料详情
 */

public class ExposureDetailPest {

    private IExposureDetailView detailView;

    public ExposureDetailPest(IExposureDetailView detailView) {
        this.detailView = detailView;
    }

    /**
     * 获取爆料详情
     * @param exposureId 爆料id
     */
    public void loadExposureDetail(String exposureId){
        Map<String,Object> map= new HashMap<>();
        map.put("newsId", exposureId);

        new ApiManager().loadExposureDetail(map, new BaseCallBack<ReplyUserBean.BaseResult<ExposureDetailBean>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<ExposureDetailBean> response) {
                detailView.loadExposureDetail(response.getData());
            }
            @Override
            public void onFailures(String message) {
                detailView.showError(message);
            }
        });

    }

    /**
     * 删除爆料
     * @param exposureId 爆料id
     */
    public void deleteExposure(String exposureId){
        Map<String,Object> map= HeadParamBean.getHead();
        map.put("ids", exposureId);
        new ApiManager().deleteExposure(map, new BaseCallBack<ReplyUserBean.BaseResult<Boolean>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<Boolean> response) {
                if (response.getData()) {
                    detailView.deleteExposure("删除成功");
                }else {
                    detailView.showError(response.getMsg());
                }
            }
            @Override
            public void onFailures(String message) {
                detailView.showError(message);
            }
        });

    }

    /**
     * 爆料点赞
     * @param exposureId 爆料id
     */
    public void praiseExposure(String exposureId){
        Map<String,Object> map= HeadParamBean.getHead();
        map.put("newsId", exposureId);
        new ApiManager().praiseExposure(map, new BaseCallBack<ReplyUserBean.BaseResult<Integer>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<Integer> response) {
                detailView.deleteExposure(response.getData()+"");
            }
            @Override
            public void onFailures(String message) {
                detailView.showError(message);
            }
        });
    }

    /**
     *  回复列表
     * @param dataId 数据id
     * @param page 页数
     * @param rows 条数
     */
    public void replyExposureList(String dataId, int page, final int rows){
        Map<String,Object> map= new HashMap<>();
        map.put("dataId", dataId);
        map.put("page", page);
        map.put("rows", rows);
        new ApiManager().replyExposureList(map, new BaseCallBack<ReplyUserBean.BaseResult<BasePageListBean<CommentBean>>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<BasePageListBean<CommentBean>> response) {
                detailView.loadExposureReplyList(response.getData().rows,response.getData().records);
            }
            @Override
            public void onFailures(String message) {
                detailView.showError(message);
            }
        });
    }

    /**
     * 爆料回复
     * @param dataId 数据id
     * @param content 内容
     */
    public void replyExposure(String dataId,String content){
        Map<String,Object> map= HeadParamBean.getHead();
        map.put("dataId", dataId);
        map.put("content", content);
        new ApiManager().replyExposure(map, new BaseCallBack<ReplyUserBean.BaseResult<Void>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<Void> response) {
                detailView.deleteExposure("评论成功");
            }
            @Override
            public void onFailures(String message) {
                detailView.showError(message);
            }
        });
    }

    /**
     * 爆料回复删除
     * @param dataId 数据id
     */
    public void replyExposureDelete(String dataId){
        Map<String,Object> map= HeadParamBean.getHead();
        map.put("id", dataId);
        new ApiManager().replyExposureDelete(map, new BaseCallBack<ReplyUserBean.BaseResult<Boolean>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<Boolean> response) {
                detailView.deleteExposure("删除回复");
            }
            @Override
            public void onFailures(String message) {
                detailView.showError(message);
            }
        });
    }
}
